/*
eax syscall number
ebx first parameter
ecx second parameter
edx third parameter
*/

.section .data
sys_call_table:
    .long 0
    .long sys_write
    .long sys_read
    .long sys_fork
    .long sys_yield
    .long sys_wait
    .long sys_exit
    .long sys_getpid
    .long sys_open
    .long sys_pause
    .long sys_waitpid
    .long sys_chdir
    .long sys_fsync
    .long sys_readdir
    .long sys_dup
    .long sys_dup2
    .long sys_getcwd
    .long sys_rename
    .long sys_mount
    .long sys_umount
    .long sys_mkdir
    .long sys_rmdir
    .long sys_lseek
    .long sys_sleep
    .long sys_fchdir
    .long sys_realpathof
    .long sys_swapon
    .long sys_execve
    .long sys_mmap
    .long sys_time


.global syscall_handler, sys_call_table
.text
syscall_handler:
    // xchg %bx, %bx
    pushl %ebp
    movl 8(%esp), %ebp // get the pointer of isr_param, skip ebp and return point
    movl (%ebp), %eax // get the syscall number
    
    // push all parameters into stack
    pushl 20(%ebp) // 5
    pushl 16(%ebp) // 4
    pushl 12(%ebp) // 3
    pushl  8(%ebp) // 2
    pushl  4(%ebp) // 1
    
    call *sys_call_table(, %eax, 4)

    movl %eax, (%ebp)

    addl $20, %esp
    popl %ebp

    ret